<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <!--  -->
      <div class="x-pro-list">
        <div class="x-pro-top">值班留言</div>
        <div v-for="(item,index) in notedata" :key="item.key">
          <div class="x-pro-row">
            <div class="x-pro-input">
              <el-input placeholder="请输入" v-model="item.content" type="textarea" :rows="3"></el-input>
            </div>
          </div>
          <div class="x-pro-remove" @click="removeentrywork(index)" v-show="!isfromindex">删除</div>
        </div>

        <div class="x-pro-addbox" @click="goonentrywork"  v-show="!isfromindex"><span class="x-pro-addicon"></span>添加</div>
      </div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-show="!isfromindex">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          persondata:'',
          tabledata:'',
          notedata:[{
            'content':'',
            'index':0
          }],
          entryworkindex:0,
          isfromindex:false,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.backshow()

      },
      methods: {
        //回显
        backshow:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/duty/getMsg',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                if(ret.data.list!=''){
                  that.notedata = ret.data.list;
                }


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //提交
        isok:function(){
          var that = this;
          api.ajax({
            url:baseurl+'api/duty/setMsg',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                msg_json:that.notedata

              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.confirm({
                    title: '保存成功',
                    msg: '',
                    buttons: ['继续编辑', '返回']
                }, function(ret, err) {
                    var index = ret.buttonIndex;
                    if(index=='1'){

                    }else{


                    }
                });

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //删除
        removeentrywork:function(index){
          let that = this;
          var nowin = index;
          console.log(JSON.stringify(that.notedata));
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.notedata.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.notedata));
            }
          });
        },
        //添加
        goonentrywork:function(){
          var that = this;
          that.entryworkindex++
          that.notedata.push({
            'title':'',
            'index':that.entryworkindex,
          });
        },
      }
    })
	}


	</script>
</body>
</html>
